package com.ktg.mes.chanjet.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.utils.StringUtils;
import com.ktg.mes.chanjet.entity.TpItem;
import com.ktg.mes.chanjet.mapper.TpItemMapper;
import com.ktg.mes.chanjet.service.TpItemService;
import com.ktg.mes.md.domain.MdItem;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TpItemServiceImpl extends ServiceImpl<TpItemMapper, TpItem> implements TpItemService{


    @Override
    public List<TpItem> selectTpItemList(TpItem tpItem) {
        return getBaseMapper().selectTpItemList(tpItem);
    }

    @Override
    public String checkItemCodeUnique(TpItem tpItem) {
        TpItem item = getBaseMapper().checkItemCodeUnique(tpItem);
        Long itemId = tpItem.getItemId() == null? -1L:tpItem.getItemId();
        if(StringUtils.isNotNull(item) && item.getItemId().longValue() != itemId.longValue()){
            return UserConstants.NOT_UNIQUE;
        }else{
            return UserConstants.UNIQUE;
        }
    }

    @Override
    public String checkItemNameUnique(TpItem tpItem) {
        TpItem item = getBaseMapper().checkItemNameUnique(tpItem);
        Long itemId = tpItem.getItemId() == null? -1L:tpItem.getItemId();
        if(StringUtils.isNotNull(item) && item.getItemId().longValue() != itemId.longValue()){
            return UserConstants.NOT_UNIQUE;
        }else{
            return UserConstants.UNIQUE;
        }
    }
}
